<template>
  <input
    type="text"
    class="myinput"
    :[propname]="{ success: flag, error: !flag }"
    @input="handlerInput"
    @blur="handlerBlur"
  />
</template>

<script>
export default {
  props: {
    rules: {
      type: RegExp,
    },
    message: {
      type: String,
      default: '数据输入不正确'
    }
  },
  data() {
    return {
      flag: "",
      propname: "",
    };
  },
  methods: {
    handlerInput(e) {
      // e 传的是InputEvent
      // console.dir(e);
      let v = e.target.value;
      this.$emit("input", v);
    },
    handlerBlur(e) {
      let v = e.target.value;
      if (this.rules) {
        this.propname = "class";
        if (this.rules.test(v)) {
          this.flag = true;
        } else {
          // 使用轻提示
          this.$toast.fail(this.message)
          this.flag = false;
        }
      }
    },
  },
};
</script>

<style lang="less" scoped>
input::-webkit-input-placeholder {
    color: #fefefc;
}
.myinput {
  box-sizing: border-box;
  padding-left:12/360 * 100vw;
  width: 318/360 * 100vw;
  height: 60px;
  outline: none;
  border: 3px solid #fff;
  // border-bottom: 3px solid #ccc;
  border-radius:70px ;
  font-size: 18/360 * 100vw;
  line-height: 60px;
  background-color: transparent;
  color: #fff;
  
}
.success {
  // border-bottom-color: green;
    border-color: green;
}
.error {
  // border-bottom-color: red;
   border-color: red;
}
</style>]